﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mjudoku.sudokuTasks;

namespace Mjudoku
{
    public partial class StartForm : Form
    {
        private Controller controller;

        public StartForm(Controller cont)
        {
            InitializeComponent();
            controller = cont;
        }

        private void buttonRun_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex > -1) {
                string[] data = comboBox1.GetItemText(comboBox1.Items[comboBox1.SelectedIndex]).Split('x');
                int size = Convert.ToInt32(data[0]);
                if (size == 0) {
                    size = 9;
                }
                TaskLoader loader = new SimpleTaskLoader();

                Object source = null;
                try
                {
                    source = loader.loadTask(size);
                }
                catch (Exception ex) {
                    MessageBox.Show("Nepoařilo se načíst sudoku z disku. " + ex, "Chyba");
                    this.Close();
                    return;
                }

                controller.initGame((int)Math.Sqrt(size), size, source);

                this.Hide();
            }
            else
            {
                MessageBox.Show("Vyber velikost.", "Velikost!");
            }
        }
    }
}
